{include file="common/header"/}
<div class="LM-container">
    <div class="LM-main">
        <div class="admin-main layui-anim layui-anim-upbit">
            <fieldset class="layui-elem-field layui-field-title">
                <legend>{$title}</legend>
            </fieldset>
            <form class="layui-form layui-form-pane" lay-filter="form">
                <div class="layui-form-item">
                    <label class="layui-form-label">字段名称</label>
                    <div class="layui-input-inline">
                        <input type="text" name="field" lay-verify="required" placeholder="字段名称" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">字母、数字组成，并且仅能字母开头</div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">字段别名</label>
                    <div class="layui-input-inline">
                        <input type="text" name="name" lay-verify="required" placeholder="字段别名" class="layui-input">
                    </div>
                    <div class="layui-form-mid layui-word-aux">中文名</div>

                </div>
                
                <div class="layui-form-item">
                    <label class="layui-form-label">字段类型</label>
                    <div class="layui-input-inline">
                        <select name="type" lay-filter="type" lay-verify="required">
                            <option></option>
                            {volist name="fieldType" id="vo"}
                            <option value="{$vo.name}" data-define="{$vo.default_define}" data-ifoption="{$vo.isoption}" data-ifstring="{$vo.istring}">{$vo.title}</option>
                            {/volist}
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">字段定义</label>
                    <div class="layui-input-inline">
                        <input type="text" name="field_define" lay-verify="required" autocomplete="off" placeholder="字段定义" class="layui-input" id="define">
                    </div>
                    <div class="layui-input-inline">
                        <select lay-filter="fasttype">
                            <option data-define="">请选择</option>
                            <option data-define="varchar(255) NOT NULL DEFAULT ''">255个字符串以内</option>
                            <option data-define="int(11) NOT NULL DEFAULT '0'">11位以内纯数字</option>
                            <option data-define="tinyint(2) NOT NULL DEFAULT '0'">2位以内纯数字</option>
                            <option data-define="float NOT NULL DEFAULT '0'">浮点</option>
                            <option data-define="text NOT NULL">常用文本文档</option>
                            <option data-define="decimal(10,2) unsigned NOT NULL">价格</option>
                            <option data-define="mediumtext NOT NULL">巨型文本文档</option>
                            <option data-define="json NOT NULL DEFAULT '0'">json数据</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">数据校验</label>
                    <div class="layui-input-inline ">
                        <input type="text" name="rule" autocomplete="off" placeholder="正则校验数据合法性，留空不校验" class="layui-input" id="rule">
                    </div>
                    <div class="layui-input-inline">
                        <select lay-filter="rule">
                            <option data-define="">常用正则</option>
                            <option data-define="/^[0-9.-]+$/">数字</option>
                            <option data-define="/^[0-9-]+$/">整数</option>
                            <option data-define="/^[a-z]+$/i">字母</option>
                            <option data-define="/^[0-9a-z]+$/i">数字+字母</option>
                            <option data-define="/^[\x{4e00}-\x{9fa5}]+$/u">中文</option>
                            <option data-define="/^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/">E-mail</option>
                            <option data-define="/^[0-9]{5,20}$/">QQ</option>
                            <option data-define="/^http:\/\//">超级链接</option>
                            <option data-define="/^(1)[0-9]{10}$/">手机号码</option>
                            <option data-define="/^[0-9-]{6,13}$/">电话号码</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">提示信息</label>
                    <div class="layui-input-inline">
                        <input type="text" name="errortips" placeholder="数据校验未通过的提示信息" class="layui-input">
                    </div>
                </div>
                <div id="options" style="display:none">
                    <div class="layui-form-item">
                        <label class="layui-form-label">选项</label>
                        <div class="layui-input-inline ">
                        <textarea name="options" placeholder="键:值
键:值
键:值"class="layui-textarea"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">字段默认值</label>
                        <div class="layui-input-inline">
                            <input type="text" name="value" lay-verify="value" autocomplete="off" placeholder="默认插入字段的值" class="layui-input">
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">是否必填</label>
                    <div class="layui-input-inline">
                        <input type="radio" name="required" value="1" title="是" >
                        <input type="radio" name="required" value="0" title="否" checked>
                    </div>
                </div>
                <div class="layui-form-item" id="is_search" style="display:none">
                    <label class="layui-form-label">是否可搜索</label>
                    <div class="layui-input-inline">
                        <input type="radio" name="is_search" value="1" title="是">
                        <input type="radio" name="is_search" value="0" title="否" checked>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-inline">
                        <input type="radio" name="status" value="1" title="启用" checked>
                        <input type="radio" name="status" value="0" title="禁用">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">排序</label>
                    <div class="layui-input-inline">
                        <input type="text" name="sort" value="50" class="layui-input" >
                    </div>
                </div>
                <input name="moduleid" type="hidden" value="{$moduleid}" />
                <input name="fieldid" type="hidden" value="{$info.id}" />
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit="" lay-filter="submit">立即提交</button>
                        {if !$info}
                        <a href="{:url('field')}?id={$moduleid}" class="layui-btn layui-btn-normal" type="button" >返回</a>
                        {/if}
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
{include file="common/footer"/}
<script>
    layui.use(['form'], function () {
        var form = layui.form,$= layui.jquery;
        var info = '';
        info = {:json_encode($info)};
        form.val("form", info);

        form.on('submit(submit)', function (data) {
            loading =layer.load(1, {shade: [0.1,'#fff']});
            // 提交到方法 默认为本身
            $.post("", data.field, function (res) {
                layer.close(loading);
                if (res.code > 0) {
                    layer.msg(res.msg, {time: 1000, icon: 1}, function () {
                        layer.closeAll("iframe");
                        //刷新父页面
                        location.reload();
                    });
                } else {
                    layer.msg(res.msg, {time: 1000, icon: 2});
                }
            });
            return false;
        })
        form.on('select(type)', function(data) {
            $('#define').val($(data.elem).find("option:selected").attr("data-define"));
            var ifoption = $(data.elem).find("option:selected").attr("data-ifoption");
            var ifstring = $(data.elem).find("option:selected").attr("data-ifstring");
            //搜索隐显
            if (ifstring == '1') {
                $('#is_search').show();
            } else {
                $('#is_search').hide();
            }
            if (ifoption == '1') {
                $('#options').show();
            } else {
                $('#options').hide();
            }
        });
        form.on('select(fasttype)', function(data) {
            $('#define').val($(data.elem).find("option:selected").attr("data-define"));
        });
        form.on('select(rule)', function(data) {
            $('#rule').val($(data.elem).find("option:selected").attr("data-define"));
        });
    });
</script>